<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RoleRealm - 对话</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'PingFang SC', 'Inter', sans-serif;
            background: #f1f5f9;
            height: 100vh;
            display: flex;
            flex-direction: column;
        }

        .chat-header {
            background: white;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            padding: 15px 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            z-index: 100;
        }

        .character-info {
            display: flex;
            align-items: center;
            gap: 15px;
        }

        .character-avatar {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            background: linear-gradient(135deg, #3b82f6, #1e3a8a);
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 20px;
            font-weight: bold;
        }

        .character-details h2 {
            color: #1e3a8a;
            font-size: 18px;
            margin-bottom: 4px;
        }

        .character-status {
            display: flex;
            align-items: center;
            gap: 8px;
            font-size: 12px;
            color: #6b7280;
        }

        .status-dot {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: #10b981;
            animation: pulse 2s infinite;
        }

        @keyframes pulse {
            0%, 100% { opacity: 1; }
            50% { opacity: 0.5; }
        }

        .header-actions {
            display: flex;
            gap: 10px;
        }

        .header-btn {
            padding: 8px 16px;
            border: none;
            border-radius: 20px;
            background: #f8fafc;
            color: #1e3a8a;
            cursor: pointer;
            font-size: 14px;
            transition: all 0.3s ease;
        }

        .header-btn:hover {
            background: #e5e7eb;
        }

        .header-btn.primary {
            background: #f59e0b;
            color: white;
        }

        .header-btn.primary:hover {
            background: #d97706;
        }

        .chat-container {
            flex: 1;
            display: grid;
            grid-template-columns: 250px 1fr 300px;
            gap: 0;
            overflow: hidden;
        }

        .chat-history {
            background: white;
            border-right: 1px solid #e5e7eb;
            overflow-y: auto;
            padding: 20px;
        }

        .history-title {
            font-size: 16px;
            font-weight: bold;
            color: #1e3a8a;
            margin-bottom: 15px;
        }

        .history-item {
            padding: 10px;
            border-radius: 10px;
            margin-bottom: 8px;
            cursor: pointer;
            transition: all 0.3s ease;
            border: 1px solid transparent;
        }

        .history-item:hover {
            background: #f8fafc;
            border-color: #e5e7eb;
        }

        .history-item.active {
            background: #dbeafe;
            border-color: #3b82f6;
        }

        .history-character {
            font-size: 12px;
            font-weight: bold;
            color: #1e3a8a;
            margin-bottom: 4px;
        }

        .history-preview {
            font-size: 11px;
            color: #6b7280;
            line-height: 1.4;
        }

        .chat-messages {
            display: flex;
            flex-direction: column;
            overflow-y: auto;
            padding: 20px;
            gap: 15px;
        }

        .message {
            display: flex;
            gap: 10px;
            max-width: 80%;
        }

        .message.user {
            align-self: flex-end;
            flex-direction: row-reverse;
        }

        .message-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 16px;
            font-weight: bold;
            flex-shrink: 0;
        }

        .message.user .message-avatar {
            background: linear-gradient(135deg, #3b82f6, #1d4ed8);
        }

        .message.ai .message-avatar {
            background: linear-gradient(135deg, #6b7280, #4b5563);
        }

        .message-content {
            background: white;
            padding: 12px 16px;
            border-radius: 18px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
            position: relative;
        }

        .message.user .message-content {
            background: linear-gradient(135deg, #3b82f6, #1d4ed8);
            color: white;
        }

        .message-text {
            font-size: 14px;
            line-height: 1.5;
            margin-bottom: 8px;
        }

        .message-time {
            font-size: 11px;
            color: #9ca3af;
        }

        .message.user .message-time {
            color: rgba(255, 255, 255, 0.7);
        }

        .message-actions {
            display: flex;
            gap: 8px;
            margin-top: 8px;
        }

        .message-action {
            padding: 4px 8px;
            background: #f8fafc;
            border: none;
            border-radius: 12px;
            font-size: 11px;
            color: #6b7280;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .message-action:hover {
            background: #e5e7eb;
        }

        .typing-indicator {
            display: none;
            align-items: center;
            gap: 10px;
            padding: 10px 0;
        }

        .typing-dots {
            display: flex;
            gap: 4px;
        }

        .typing-dot {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: #9ca3af;
            animation: typing 1.4s infinite;
        }

        .typing-dot:nth-child(2) {
            animation-delay: 0.2s;
        }

        .typing-dot:nth-child(3) {
            animation-delay: 0.4s;
        }

        @keyframes typing {
            0%, 60%, 100% {
                transform: translateY(0);
            }
            30% {
                transform: translateY(-10px);
            }
        }

        .character-panel {
            background: white;
            border-left: 1px solid #e5e7eb;
            padding: 20px;
            overflow-y: auto;
        }

        .panel-title {
            font-size: 16px;
            font-weight: bold;
            color: #1e3a8a;
            margin-bottom: 15px;
        }

        .character-background {
            margin-bottom: 20px;
        }

        .background-title {
            font-size: 14px;
            font-weight: bold;
            color: #374151;
            margin-bottom: 8px;
        }

        .background-text {
            font-size: 12px;
            color: #6b7280;
            line-height: 1.5;
        }

        .character-skills {
            margin-bottom: 20px;
        }

        .skills-title {
            font-size: 14px;
            font-weight: bold;
            color: #374151;
            margin-bottom: 8px;
        }

        .skill-tags {
            display: flex;
            flex-wrap: wrap;
            gap: 6px;
        }

        .skill-tag {
            padding: 4px 8px;
            background: #fef3c7;
            color: #92400e;
            border-radius: 12px;
            font-size: 11px;
        }

        .related-characters {
            margin-bottom: 20px;
        }

        .related-title {
            font-size: 14px;
            font-weight: bold;
            color: #374151;
            margin-bottom: 8px;
        }

        .related-item {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 8px;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-bottom: 6px;
        }

        .related-item:hover {
            background: #f8fafc;
        }

        .related-avatar {
            width: 30px;
            height: 30px;
            border-radius: 50%;
            background: linear-gradient(135deg, #3b82f6, #1e3a8a);
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 12px;
            font-weight: bold;
        }

        .related-name {
            font-size: 12px;
            color: #374151;
        }

        .chat-input {
            background: white;
            border-top: 1px solid #e5e7eb;
            padding: 20px;
            display: flex;
            gap: 10px;
            align-items: flex-end;
        }

        .input-container {
            flex: 1;
            position: relative;
        }

        .message-input {
            width: 100%;
            min-height: 40px;
            max-height: 120px;
            padding: 10px 50px 10px 16px;
            border: 2px solid #e5e7eb;
            border-radius: 20px;
            font-size: 14px;
            resize: none;
            outline: none;
            transition: all 0.3s ease;
        }

        .message-input:focus {
            border-color: #3b82f6;
            box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
        }

        .input-actions {
            position: absolute;
            right: 8px;
            top: 50%;
            transform: translateY(-50%);
            display: flex;
            gap: 5px;
        }

        .input-action {
            width: 24px;
            height: 24px;
            border: none;
            background: none;
            cursor: pointer;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.3s ease;
        }

        .input-action:hover {
            background: #f8fafc;
        }

        .voice-btn {
            background: #f59e0b;
            color: white;
            border: none;
            border-radius: 50%;
            width: 50px;
            height: 50px;
            cursor: pointer;
            font-size: 20px;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .voice-btn:hover {
            background: #d97706;
        }

        .voice-btn.recording {
            background: #ef4444;
            animation: pulse 1s infinite;
        }

        .send-btn {
            background: #3b82f6;
            color: white;
            border: none;
            border-radius: 50%;
            width: 50px;
            height: 50px;
            cursor: pointer;
            font-size: 16px;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .send-btn:hover {
            background: #2563eb;
        }

        .send-btn:disabled {
            background: #9ca3af;
            cursor: not-allowed;
        }

        .voice-waveform {
            display: none;
            position: absolute;
            top: -60px;
            left: 0;
            right: 0;
            background: rgba(0, 0, 0, 0.8);
            color: white;
            padding: 10px;
            border-radius: 10px;
            text-align: center;
            font-size: 12px;
        }

        .waveform-bars {
            display: flex;
            justify-content: center;
            gap: 2px;
            margin-top: 5px;
        }

        .waveform-bar {
            width: 3px;
            background: #f59e0b;
            border-radius: 2px;
            animation: waveform 0.5s infinite alternate;
        }

        .waveform-bar:nth-child(2) { animation-delay: 0.1s; }
        .waveform-bar:nth-child(3) { animation-delay: 0.2s; }
        .waveform-bar:nth-child(4) { animation-delay: 0.3s; }
        .waveform-bar:nth-child(5) { animation-delay: 0.4s; }

        @keyframes waveform {
            0% { height: 4px; }
            100% { height: 20px; }
        }

        @media (max-width: 1024px) {
            .chat-container {
                grid-template-columns: 200px 1fr;
            }
            
            .character-panel {
                display: none;
            }
        }

        @media (max-width: 768px) {
            .chat-container {
                grid-template-columns: 1fr;
            }
            
            .chat-history {
                display: none;
            }
            
            .message {
                max-width: 90%;
            }
            
            .chat-header {
                padding: 10px 15px;
            }
            
            .character-info {
                gap: 10px;
            }
            
            .character-avatar {
                width: 40px;
                height: 40px;
                font-size: 16px;
            }
            
            .character-details h2 {
                font-size: 16px;
            }
        }
    </style>
</head>
<body>
    <header class="chat-header">
        <div class="character-info">
            <div class="character-avatar" id="characterAvatar">苏</div>
            <div class="character-details">
                <h2 id="characterName">苏格拉底</h2>
                <div class="character-status">
                    <div class="status-dot"></div>
                    <span>在线</span>
                </div>
            </div>
        </div>
        <div class="header-actions">
            <button class="header-btn" onclick="toggleHistory()">历史记录</button>
            <button class="header-btn" onclick="toggleCharacterPanel()">角色信息</button>
            <button class="header-btn primary" onclick="window.location.href='character-selection.html'">返回</button>
        </div>
    </header>

    <div class="chat-container">
        <aside class="chat-history">
            <h3 class="history-title">对话历史</h3>
            <div class="history-item active">
                <div class="history-character" id="historyCharacterName">苏格拉底</div>
                <div class="history-preview" id="historyPreview">你好!我是苏格拉底。很高兴与你相遇...</div>
            </div>
            <div class="history-item">
                <div class="history-character">莎士比亚</div>
                <div class="history-preview">To be or not to be, that is the question...</div>
            </div>
            <div class="history-item">
                <div class="history-character">爱因斯坦</div>
                <div class="history-preview">想象力比知识更重要...</div>
            </div>
        </aside>

        <main class="chat-messages" id="chatMessages">
            <div class="message ai">
                <div class="message-avatar">苏</div>
                <div class="message-content">
                    <div class="message-text">你好！我是苏格拉底。很高兴与你相遇。正如我常说的："我知道我一无所知。"让我们开始一场真诚的对话吧。你想讨论什么话题呢？</div>
                    <div class="message-time">刚刚</div>
                    <div class="message-actions">
                        <button class="message-action">复制</button>
                        <button class="message-action">重播</button>
                    </div>
                </div>
            </div>

            <div class="typing-indicator" id="typingIndicator">
                <div class="message-avatar">苏</div>
                <div class="typing-dots">
                    <div class="typing-dot"></div>
                    <div class="typing-dot"></div>
                    <div class="typing-dot"></div>
                </div>
            </div>
        </main>

        <aside class="character-panel">
            <h3 class="panel-title">角色信息</h3>
            
            <div class="character-background">
                <div class="background-title">背景介绍</div>
                <div class="background-text">
                    苏格拉底（公元前470-399年）是古希腊哲学家，西方哲学的奠基者之一。他以"我知道我一无所知"的智慧闻名，通过问答法引导学生思考。他的哲学思想对后世产生了深远影响。
                </div>
            </div>

            <div class="character-skills">
                <div class="skills-title">技能标签</div>
                <div class="skill-tags">
                    <span class="skill-tag">哲学思辨</span>
                    <span class="skill-tag">问答法</span>
                    <span class="skill-tag">道德哲学</span>
                    <span class="skill-tag">知识论</span>
                </div>
            </div>

            <div class="related-characters">
                <div class="related-title">相关角色</div>
                <div class="related-item" onclick="switchCharacter('plato')">
                    <div class="related-avatar">柏</div>
                    <div class="related-name">柏拉图</div>
                </div>
                <div class="related-item" onclick="switchCharacter('aristotle')">
                    <div class="related-avatar">亚</div>
                    <div class="related-name">亚里士多德</div>
                </div>
            </div>
        </aside>
    </div>

    <div class="chat-input">
        <div class="input-container">
            <textarea class="message-input" id="messageInput" placeholder="输入消息..." rows="1"></textarea>
            <div class="input-actions">
                <button class="input-action" title="表情">😊</button>
                <button class="input-action" title="图片">📷</button>
            </div>
            <div class="voice-waveform" id="voiceWaveform">
                <div>正在录音...</div>
                <div class="waveform-bars">
                    <div class="waveform-bar"></div>
                    <div class="waveform-bar"></div>
                    <div class="waveform-bar"></div>
                    <div class="waveform-bar"></div>
                    <div class="waveform-bar"></div>
                </div>
            </div>
        </div>
        <button class="voice-btn" id="voiceBtn" title="按住说话">🎤</button>
        <button class="send-btn" id="sendBtn" title="发送">➤</button>
    </div>

    <script>
        // 角色数据
        const characters = {
            socrates: { 
                name: '苏格拉底', 
                avatar: '苏', 
                background: '古希腊哲学家，西方哲学的奠基者之一。他以"我知道我一无所知"的智慧闻名，通过问答法引导学生思考。',
                intro: '你好!我是苏格拉底。很高兴与你相遇。正如我常说的:"我知道我一无所知。"让我们开始一场真诚的对话吧。你想讨论什么话题呢?'
            },
            shakespeare: { 
                name: '莎士比亚', 
                avatar: '莎', 
                background: '英国文学巨匠，创作了《哈姆雷特》《罗密欧与朱丽叶》等经典作品。',
                intro: '欢迎，我的朋友!我是威廉·莎士比亚。正如我在《哈姆雷特》中所写:"生存还是毁灭，这是一个值得考虑的问题。"让我们用诗意的语言来探讨人生的奥秘吧。'
            },
            einstein: { 
                name: '爱因斯坦', 
                avatar: '爱', 
                background: '理论物理学家，相对论的创立者，诺贝尔物理学奖获得者。',
                intro: '你好!我是阿尔伯特·爱因斯坦。正如我所说:"想象力比知识更重要。"让我们一起来探索宇宙的奥秘和科学的真理吧。'
            },
            conan: {
                name: '江户川柯南',
                avatar: '柯',
                background: '天才侦探，被黑衣组织灌下毒药变成小学生的工藤新一。',
                intro: '啊咧咧，你好!我是江户川柯南，不过其实我是工藤新一。有什么谜题需要我帮忙解决吗?在我眼中，任何案件都像小学生作业一样简单呢!'
            }
        };

        // 获取URL参数
        const urlParams = new URLSearchParams(window.location.search);
        const characterId = urlParams.get('character') || 'socrates';
        const currentCharacter = characters[characterId] || characters.socrates;

        // 初始化角色信息
        document.getElementById('characterName').textContent = currentCharacter.name;
        document.getElementById('characterAvatar').textContent = currentCharacter.avatar;
        
        // 更新历史记录显示
        document.getElementById('historyCharacterName').textContent = currentCharacter.name;
        document.getElementById('historyPreview').textContent = currentCharacter.intro.substring(0, 30) + '...';

        // 检查是否是新的对话，如果是则发送角色自我介绍
        const chatMessages = document.getElementById('chatMessages');
        const existingMessages = chatMessages.querySelectorAll('.message');
        
        // 如果没有现有消息，发送角色自我介绍
        if (existingMessages.length === 0) {
            setTimeout(() => {
                callRoleplayIntro();
            }, 1000); // 延迟1秒显示，让用户感受到角色主动打招呼
        }

        async function callRoleplayIntro() {
            try {
                const response = await fetch('http://localhost:8080/api/test/roleplay', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        character: currentCharacter.name,
                        prompt: '请以' + currentCharacter.name + '的身份主动向我打招呼，介绍你自己，并邀请我与你对话。'
                    })
                });

                if (!response.ok) {
                    throw new Error(`HTTP ${response.status}: ${response.statusText}`);
                }

                const data = await response.json();
                
                if (data.success && data.data) {
                    addMessage(data.data, 'ai');
                } else {
                    // 如果API调用失败，使用预设的自我介绍
                    addMessage(currentCharacter.intro, 'ai');
                }
            } catch (error) {
                console.error('调用角色自我介绍API失败:', error);
                // 如果API调用失败，使用预设的自我介绍
                addMessage(currentCharacter.intro, 'ai');
            }
        }

        // 消息输入和发送
        const messageInput = document.getElementById('messageInput');
        const sendBtn = document.getElementById('sendBtn');
        const typingIndicator = document.getElementById('typingIndicator');

        messageInput.addEventListener('input', function() {
            this.style.height = 'auto';
            this.style.height = Math.min(this.scrollHeight, 120) + 'px';
            
            sendBtn.disabled = !this.value.trim();
        });

        messageInput.addEventListener('keydown', function(e) {
            if (e.key === 'Enter' && !e.shiftKey) {
                e.preventDefault();
                sendMessage();
            }
        });

        sendBtn.addEventListener('click', sendMessage);

        function sendMessage() {
            const message = messageInput.value.trim();
            if (!message) return;

            // 添加用户消息
            addMessage(message, 'user');
            messageInput.value = '';
            messageInput.style.height = 'auto';
            sendBtn.disabled = true;

            // 显示打字指示器
            showTypingIndicator();

            // 调用后端角色扮演API
            callRoleplayAPI(message);
        }

        async function callRoleplayAPI(userMessage) {
            try {
                const response = await fetch('http://localhost:8080/api/test/roleplay', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        character: currentCharacter.name,
                        prompt: userMessage
                    })
                });

                if (!response.ok) {
                    throw new Error(`HTTP ${response.status}: ${response.statusText}`);
                }

                const data = await response.json();
                
                // 隐藏打字指示器
                hideTypingIndicator();
                
                if (data.success && data.data) {
                    addMessage(data.data, 'ai');
                } else {
                    addMessage('抱歉，AI服务暂时不可用，请稍后重试。', 'ai');
                }
            } catch (error) {
                console.error('调用角色扮演API失败:', error);
                hideTypingIndicator();
                addMessage('抱歉，AI服务出现异常，请稍后重试。', 'ai');
            }
        }

        function addMessage(text, sender) {
            const messageDiv = document.createElement('div');
            messageDiv.className = `message ${sender}`;
            
            const avatar = sender === 'user' ? '你' : currentCharacter.avatar;
            const time = new Date().toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' });
            
            messageDiv.innerHTML = `
                <div class="message-avatar">${avatar}</div>
                <div class="message-content">
                    <div class="message-text">${text}</div>
                    <div class="message-time">${time}</div>
                    <div class="message-actions">
                        <button class="message-action">复制</button>
                        ${sender === 'ai' ? '<button class="message-action">重播</button>' : ''}
                    </div>
                </div>
            `;
            
            chatMessages.appendChild(messageDiv);
            chatMessages.scrollTop = chatMessages.scrollHeight;
        }

        function showTypingIndicator() {
            typingIndicator.style.display = 'flex';
            chatMessages.scrollTop = chatMessages.scrollHeight;
        }

        function hideTypingIndicator() {
            typingIndicator.style.display = 'none';
        }

        function generateAIResponse(userMessage) {
            const responses = {
                socrates: [
                    "这是一个很有趣的问题。让我们用问答法来探讨一下：你认为什么是真正的智慧？",
                    "正如我常说的，'未经审视的生活不值得过。'让我们深入思考这个问题。",
                    "我注意到你提到了一个重要的观点。让我们通过对话来发现真理。",
                    "你的问题让我想起了我的老师曾经说过的话。让我们一起来探索这个问题的本质。",
                    "啊，你提出了一个深刻的问题。正如我所相信的，真正的智慧来自于承认自己的无知。"
                ],
                shakespeare: [
                    "To be or not to be, that is the question. 你提到的这个问题让我想起了哈姆雷特的内心独白。",
                    "正如我在《罗密欧与朱丽叶》中写道：'玫瑰不叫玫瑰，依然芬芳如故。'",
                    "你的话语如诗如画，让我想起了我创作的那些经典台词。",
                    "让我们用戏剧的方式来探讨这个问题，就像我在舞台上展现的那样。",
                    "多么富有诗意的问题啊！正如我在《暴风雨》中所写：'我们都是梦的材料。'"
                ],
                einstein: [
                    "想象力比知识更重要，因为知识是有限的，而想象力概括着世界的一切。",
                    "你提出的问题让我想起了相对论。让我们从科学的角度来思考。",
                    "正如我所说，'疯狂就是一遍又一遍地做同样的事情，却期望得到不同的结果。'",
                    "你的问题很有启发性。让我们用科学的方法来探索这个现象。",
                    "这让我想起了E=mc²。在宇宙中，一切都有其内在的联系和规律。"
                ],
                conan: [
                    "啊咧咧，这个问题很有意思呢！让我用推理来帮你分析一下。",
                    "真相只有一个！根据我的观察，这里有几个疑点需要调查。",
                    "（扶了扶眼镜，镜片闪过一道白光）这个案件比我想象的还要复杂。",
                    "在我眼中，这个问题就像小学生作业一样简单。让我来为你推理一下。",
                    "工藤新一的推理时间到了！让我用逻辑来解开这个谜题。"
                ]
            };
            
            const characterResponses = responses[characterId] || responses.socrates;
            return characterResponses[Math.floor(Math.random() * characterResponses.length)];
        }

        // 语音功能
        const voiceBtn = document.getElementById('voiceBtn');
        const voiceWaveform = document.getElementById('voiceWaveform');
        let isRecording = false;

        voiceBtn.addEventListener('mousedown', startRecording);
        voiceBtn.addEventListener('mouseup', stopRecording);
        voiceBtn.addEventListener('mouseleave', stopRecording);

        function startRecording() {
            isRecording = true;
            voiceBtn.classList.add('recording');
            voiceWaveform.style.display = 'block';
        }

        function stopRecording() {
            if (isRecording) {
                isRecording = false;
                voiceBtn.classList.remove('recording');
                voiceWaveform.style.display = 'none';
                
                // 模拟语音识别结果
                setTimeout(() => {
                    const recognizedText = "这是一个语音识别的示例文本";
                    messageInput.value = recognizedText;
                    messageInput.style.height = 'auto';
                    sendBtn.disabled = false;
                }, 1000);
            }
        }

        // 切换角色
        function switchCharacter(newCharacterId) {
            window.location.href = `chat.html?character=${newCharacterId}`;
        }

        // 切换历史记录面板
        function toggleHistory() {
            const history = document.querySelector('.chat-history');
            history.style.display = history.style.display === 'none' ? 'block' : 'none';
        }

        // 切换角色信息面板
        function toggleCharacterPanel() {
            const panel = document.querySelector('.character-panel');
            panel.style.display = panel.style.display === 'none' ? 'block' : 'none';
        }
    </script>
</body>
</html>
